﻿using Coldairarrow.Entity.DTO;
using Coldairarrow.Entity.PB;
using Coldairarrow.Util;
using EFCore.Sharding;
using LinqKit;
using Microsoft.EntityFrameworkCore;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Dynamic.Core;
using System.Threading.Tasks;

namespace Coldairarrow.Business.PB
{
    public partial class View_PB_DesignOutStorDetailBusiness : BaseBusiness<View_PB_DesignOutStorDetail>, IView_PB_DesignOutStorDetailBusiness, ITransientDependency
    {
        public View_PB_DesignOutStorDetailBusiness(IDbAccessor db)
            : base(db)
        {
        }

        #region 外部接口
        //朱柏清 发货通知明细物料列表 2022-03-02
        public async Task<PageResult<View_PB_DesignOutStorDetail>> GetDataListAsync(PageInput<PB_DesignDetailselectDTO> input)
        {
            var q = GetIQueryable();
            var where = LinqHelper.True<View_PB_DesignOutStorDetail>();
            var search = input.Search;
            if (!search.NoticeItemId.IsNullOrEmpty())
            {
                q = q.Where(x => x.ParentId == search.NoticeItemId);
            }
            input.SortField = "Buildingnumber";
            return await q.Where(where).GetPageResultAsync(input);
        }
        ////朱柏清 发货通知明细物料详情 2022-03-02
        public async Task<PageResult<View_PB_DesignOutStorDetail>> GetDataItemListAsync(PageInput<PB_DesignDetailselectDTO> input)
        {
            var q = GetIQueryable();
            var where = LinqHelper.True<View_PB_DesignOutStorDetail>();
            var search = input.Search;
            if (!search.Id.IsNullOrEmpty())
            {
                PB_DeliveryNoticeItem bdata = await Db.GetIQueryable<PB_DeliveryNoticeItem>().Where(x => x.Id == search.Id).FirstOrDefaultAsync();
                q = q.Where(x => x.DesignId == bdata.DesignId && x.NoticeId == search.Id);
            }
            return await q.Where(where).GetPageResultAsync(input);
        }
        public async Task<View_PB_DesignOutStorDetail> GetTheDataAsync(string id)
        {
            return await GetEntityAsync(id);
        }

        public async Task AddDataAsync(View_PB_DesignOutStorDetail data)
        {
            await InsertAsync(data);
        }

        public async Task UpdateDataAsync(View_PB_DesignOutStorDetail data)
        {
            await UpdateAsync(data);
        }

        public async Task DeleteDataAsync(List<string> ids)
        {
            await DeleteAsync(ids);
        }

        #endregion

        #region 私有成员

        #endregion
    }
}